package com.game.basic;



/**
* @author oven:
* @version 创建时间：2012-11-5 下午4:25:25
* 
*/
public class BasicRegion{
	private float postx;
	private float posty;
	private float width;
	private float height;
	
	public BasicRegion(){
		
	}
	
	public void setWithSR(float x,float y,float w,float h){
		postx=x;
		posty=y;
		this.height=h;
		this.width=w;
	}
	
	public float getPostx() {
		return postx;
	}

	public void setPostx(float postx) {
		this.postx = postx;
	}

	public float getPosty() {
		return posty;
	}

	public void setPosty(float posty) {
		this.posty = posty;
	}

	public float getWidth() {
		return width;
	}

	public void setWidth(float width) {
		this.width = width;
	}

	public float getHeight() {
		return height;
	}

	public void setHeight(float height) {
		this.height = height;
	}
	
	public float getEndx(){
		return getPostx()+getWidth();
	}
	
	public float getEndy(){
		return getPosty()+getHeight();
	}
	
	public void addPostx(float x){
		postx=postx+x;
	}
	
	public void addPosty(float y){
		posty=posty+y;
	}
	
	public void setPostWithCenterPoint(float x,float y){
		setPostxWithCenterPoint(x);
		setPostyWithCenterPoint(y);
	}
	
	public void setPostxWithCenterPoint(float x){
		setPostx(x-width/2);
	}
	
	public void setPostyWithCenterPoint(float y){
		setPosty(y-height/2);
	}
	
	public void setPostyWithBottom(float y){
		setPosty(y-height);
	}
	
	public float[] getCenterPoint(){
		float[] result = new float[2];
		result[0] = getCenterPointX();
		result[1] = getCenterPointY();
		return result;
	}
	
	public float getCenterPointX(){
		return getPostx()+getWidth()/2;
	}
	
	public float getCenterPointY(){
		return getPosty()+getHeight()/2;
	}
	
	/**
	 * 获取 四个顶点
	 * @return
	 */
	public float[] getRegionXY(){
		float[] result = new float[4];
		result[0]=getPostx();
		result[1]=getPosty();
		result[2]=getEndx();
		result[3]=getEndy();
		return result;
	}
	
	/**
	 * 获取 2个顶点 与长宽
	 * @return
	 */
	public float[] getRegionWH(){
		float[] result = new float[4];
		result[0]=getPostx();
		result[1]=getPosty();
		result[2]=getWidth();
		result[3]=getHeight();
		return result;
	}
}

